<template>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="记录编号" prop="recordCode">
            <el-input v-model="queryParams.recordCode" placeholder="请输入记录编号" clearable size="small"
                @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="商品" prop="goodsId">
            <el-select v-model="queryParams.goodsId" placeholder="请选择商品" clearable size="small">
                <el-option v-for="item in goodsOptions" :key="item.id" :label="item.goodsName" :value="item.id" />
            </el-select>
        </el-form-item>
        <el-form-item label="记录类型" prop="recordType">
            <el-select v-model="queryParams.recordType" placeholder="请选择记录类型" clearable size="small">
                <el-option v-for="dict in dict.type.stock_record_type" :key="dict.value" :label="dict.label"
                    :value="dict.value" />
            </el-select>
        </el-form-item>
        <el-form-item label="记录日期" prop="recordDate">
            <el-date-picker v-model="queryParams.recordDate" type="daterange" range-separator="至"
                start-placeholder="开始日期" end-placeholder="结束日期" size="small" />
        </el-form-item>
        <el-form-item label="审核状态" prop="approvalStatus">
            <el-select v-model="queryParams.approvalStatus" placeholder="请选择审核状态" clearable size="small">
                <el-option v-for="dict in dict.type.stock_approval_status" :key="dict.value" :label="dict.label"
                    :value="dict.value" />
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
import { listGoods } from "@/api/system/goods";

export default {
    name: "RecordSearch",
    dicts: ['stock_record_type', 'stock_approval_status'],
    props: {
        // 显示搜索条件
        showSearch: {
            type: Boolean,
            default: true
        },
        // 查询参数
        queryParams: {
            type: Object,
            default: () => {
                return {
                    pageNum: 1,
                    pageSize: 10,
                    recordCode: null,
                    goodsId: null,
                    recordType: null,
                    recordDate: null,
                    approvalStatus: null
                };
            }
        }
    },
    data() {
        return {
            // 商品选项
            goodsOptions: []
        };
    },
    created() {
        this.getGoodsOptions();
    },
    methods: {
        /** 查询商品选项 */
        getGoodsOptions() {
            listGoods().then(response => {
                this.goodsOptions = response.rows;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.$emit('query', this.queryParams);
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.$emit('reset', this.queryParams);
        }
    }
};
</script>

<style lang="scss" scoped>
.record-search {
    .record-search-item {
        margin-bottom: 20px;

        .record-search-label {
            font-weight: bold;
            color: #606266;
        }

        .record-search-input {
            width: 100%;
        }
    }
}
</style>